<?php

namespace App\Services\Game\Data\Log\Elasticsearch;

use App\Services\Service;
use App\Services\Traits\DatabaseElasticsearch;
use App\Models\Elasticsearch\Log\Cost as Log;

class CostService extends Service
{
    use DatabaseElasticsearch;

    /**
     * 获取数据列表
     *
     * @param \Illuminate\Http\Request $request
     * @return array[]|int[]|array[]
     */
    public function getList($request)
    {
        $params = ['body' => ['track_total_hits' => true]];

        // 筛选【平台】
        $this->makeWhereParamOrg($request, $params);
        // 筛选【时间】
	    $this->makeWhereParamDatetime($request, $params, null, 'datetime', Log::INDEX_NAME, '', '', 'default');
        // 筛选【类型】
        $this->makeWhereParam($request, 'cost_type', $params);
        // 筛选【搜索】
        $this->makeWhereParamSearch($request, $params);

        // 排序分页
        $this->makeOrderParam($request, $params)->makePaginationParam($request, $params);
        // 第二排序
        $this->makeOrderParam($request, $params, 'id');
	    $this->makeWhereParam($request, 'currency', $params);


	    // 查询数据
        $results = Log::search($params);

        // 数据列表
        $datas = $results['hits']['hits'];
        // 数据条数
        $total = $results['hits']['total']['value'];

        return [
            $datas,
            $total
        ];
    }
}
